<?php

namespace aes;


class AesJs
{
    public static function init($iv = '')
    {
        self::$iv = $iv;
    }

    /**
     * 加密字符串
     * @param string $data 字符串
     * @param string $key  加密key
     * @return string
     */
    public static function encrypt($data, $key,$iv)
    {
        $encode = base64_encode(openssl_encrypt($data,"AES-128-CBC",$key,true,$iv));
        return $encode;
    }

    /**
     * 解密字符串
     * @param string $data 字符串
     * @param string $key  加密key
     * @return string
     */
    public static function decrypt($data, $key,$iv)
    {

        $decrypted = openssl_decrypt(base64_decode($data),"AES-128-CBC",$key,true,$iv);
        return $decrypted;
    }
}

?>